package com.cn.esermis;

import com.cn.esermis.server.BootNettyServer;
import com.cn.esermis.server.Consumer;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

@SpringBootApplication(exclude = {
        DataSourceAutoConfiguration.class,
})
@EnableScheduling // 启用定时任务
@EnableAsync
@MapperScan(value = {"com.cn.esermis.**.mapper"})
public class EsermisApplication  implements CommandLineRunner {
    public static void main(String[] args){
        ConfigurableApplicationContext context =  SpringApplication.run(EsermisApplication.class, args);
        // 调用异步任务 启动消费服务
        context.getBean(Consumer.class).receive();
        context.getBean(Consumer.class).receiveRepeat();
    }
    //异步方法
    @Async
    public void run(String... args) throws Exception {
        /**
         * 使用异步注解方式启动netty服务端服务
         */
//        new BootNettyServer().bind(19900);
        new BootNettyServer().bind(8088);
    }

}
